package cn.jasonone.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.jasonone.bean.SysResource;
import cn.jasonone.mapper.SysResourceMapper;
import cn.jasonone.service.SysResourceService;
@Service
public class SysResourceServiceImpl implements SysResourceService {
	@Resource
	private SysResourceMapper sysResourceMapper;
	@Override
	public boolean save(SysResource sysResource) {
		return sysResourceMapper.save(sysResource)>0;
	}

	@Override
	public boolean deleteByIds(int... ids) {
		return sysResourceMapper.deleteByIds(ids)>0;
	}

	@Override
	public List<SysResource> findAll(SysResource sysResource) {
		return sysResourceMapper.findAll(sysResource);
	}

	@Override
	public SysResource findById(int id) {
		return sysResourceMapper.findById(id);
	}

	@Override
	public List<SysResource> findByRoleId(int roleId) {
		return sysResourceMapper.findByRoleId(roleId);
	}
	@Transactional
	@Override
	public boolean bindRole(int roleId, int[] resourceIds) {
		sysResourceMapper.deleteResourceBind(roleId);
		sysResourceMapper.addResourceBind(roleId, resourceIds);
		return true;
	}

}
